import { createStore } from 'vuex'

export default createStore({
  state: {
    up:sessionStorage.getItem('up')||JSON.stringify({}),
    userRole:sessionStorage.getItem('userRole') || null,
    globalLatifundiumId:sessionStorage.getItem('globalLatifundiumId') || null,
    userInfo:sessionStorage.getItem('userInfo')?JSON.parse(sessionStorage.getItem('userInfo')):{
      userId:"",
      name:'',
      rk:'',
    },
    farmList:sessionStorage.getItem('farmList')?JSON.parse(sessionStorage.getItem('farmList')):[],
    datavColors: ['rgb(46, 96, 153)', 'rgb(124, 231, 253)'],
    theme: 0,
    expires_time: sessionStorage.getItem('expires_time') || null,//token过期时间
    ACCESS_TOKEN: sessionStorage.getItem('access_token') || null,
    REFRESH_TOKEN: sessionStorage.getItem('refresh_token') || null,
    menuList:[
      {
        name:'农场地图',
        icon:require('@/assets/img/menuIcon_0.png'),
        img:require('@/assets/img/menuImg_0.png'),
        children:[]
      },
      {
        name:'农场信息',
        icon:require('@/assets/img/menuIcon_1.png'),
        img:require('@/assets/img/menuImg_1.png'),
        children:[]
      },
      {
        name:'基础设施管理',
        icon:require('@/assets/img/menuIcon_2.png'),
        img:require('@/assets/img/menuImg_2.png'),
        children:[]
      },
      {
        name:'物联网设备管理',
        icon:require('@/assets/img/menuIcon_3.png'),
        img:require('@/assets/img/menuImg_3.png'),
        children:[]
      },
      {
        name:'农机管理',
        icon:require('@/assets/img/menuIcon_3.png'),
        img:require('@/assets/img/menuImg_3.png'),
        children:[]
      },
      {
        name:'农资管理',
        icon:require('@/assets/img/menuIcon_4.png'),
        img:require('@/assets/img/menuImg_4.png'),
        children:[]
      },
      {
        name:'农作物管理',
        icon:require('@/assets/img/menuIcon_5.png'),
        img:require('@/assets/img/menuImg_5.png'),
        children:[]
      },
      {
        name:'土壤水质数据',
        icon:require('@/assets/img/add1.png'),
        img:require('@/assets/img/adda1.png'),
        children:[]
      },
      {
        name:'农事计划管理',
        icon:require('@/assets/img/menuIcon_7.png'),
        img:require('@/assets/img/menuImg_7.png'),
        children:[
          {
            name:'农事计划列表',
            icon:require('@/assets/img/subIcon_0.png'),
            img:require('@/assets/img/subImg_0.png'),
          },
          {
            name:'农事计划审核',
            icon:require('@/assets/img/subIcon_1.png'),
            img:require('@/assets/img/subImg_1.png'),
          },
          {
            name:'农事计划模板',
            icon:require('@/assets/img/subIcon_2.png'),
            img:require('@/assets/img/subImg_2.png'),
          },
          {
            name:'农事计划信息',
            icon:require('@/assets/img/subIcon_3.png'),
            img:require('@/assets/img/subImg_3.png'),
          },
        ]
      },
    ]
  },
  getters: {
  },
  mutations: {
    changeGlobalLatifundiumId(state, value){
      state.globalLatifundiumId = value
      sessionStorage.setItem('globalLatifundiumId', value)
    },
    changeUserRole(state, value){
      state.userRole = value
      sessionStorage.setItem('userRole', value)
    },
    changeFarmList(state, value){
      state.farmList=value
      sessionStorage.setItem('farmList', JSON.stringify(value))
    },
    changeUserInfo(state, value){
      state.userInfo=value
      sessionStorage.setItem('userInfo',JSON.stringify(value))
    },
    changeDatavColors(state, value) {
      state.datavColors = value
    },
    changeTheme(state, value) {
      state.theme = value
    },
    changeExpires_time(state, value) {
      state.expires_time = value
      sessionStorage.setItem('expires_time', value)
    },
    changeACCESS_TOKEN(state, value) {
      state.ACCESS_TOKEN = value
      sessionStorage.setItem('access_token', value)
    },
    changeREFRESH_TOKEN(state, value) {
      state.REFRESH_TOKEN = value
      sessionStorage.setItem('refresh_token', value)
    },
    getUandP(state, value){
      state.up = JSON.stringify(value)
      console.log('xxxxxxvaluevaluevaluevalue',value)
      sessionStorage.setItem('up', JSON.stringify(value))
    }
  },
  actions: {
  },
  modules: {
  }
})
